
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/Jcss.css" />
<link rel="stylesheet" type="text/css"
	href="static/jquery/redmond/jquery-ui-1.9.0.custom.min.css" />

<script type="text/javascript" src="static/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript"
	src="static/jquery/jquery-ui-1.9.0.custom.min.js"></script>
<script type="text/javascript" src="static/jquery/jquery-extends.js"></script>
<script type="text/javascript"
	src="static/jquery/jquery.printElement.min.js"></script>

<script type="text/javascript">
	var bottleLogCount = 0;
	var logCount = 0;
	var logCacheCount = 200;
	function loadingBegin() {
		$('div.loading').css("display", "block");
	}
	function loadingEnd() {
		$('div.loading').css("display", "none");
	}
	var localMode = true;
	var ExternalFunctions = {
		JS2C_GetExitResult : function(callBkfunc) {
			setTimeout(callBkfunc + "('1')", 3000);
		},
		JS2C_GetParameterInfo : function() {
			return '{"pname":"我的酒","box": "3","bottle": "6","barcode": "WINE-43517293HT","plist":[{"pdid":"1","pname": "茅台酒", "barcode": "WINE-27843597MT"},{"pdid":"2","pname": "我的酒", "barcode": "WINE-43517293HT"}],"pdid": "2","pwd": "1","checked": "1", "batchid":"HT-BATCH-0093331","cbottle":"3","cbox":"1","exit":"1","v":"当前版本：v1.0"}';
		},
		JS2C_GetPasswordUpdateResult : function() {
			return "1";
		},
		JS2C_InitializeIndexInfo : function() {

		},
		JS2C_GetAllBatchId : function(callBkFunc) {

			$.ajax({
				url : 'line/getbatchlist.htm',
				type : "POST",
				success : function(data) {
					if (data != null && data != "" && data.bs
							&& data.bs.length > 0) {
						var ids = "";
						for ( var i = 0; i < data.bs.length; i++) {
							ids = ids + data.bs[i].b + ',';
						}

						if (ids != "") {
							ids = ids.substr(0, ids.length - 1);
							ids = "{'ids':'" + ids + "'}";
						}

						var evalStr = callBkFunc + '("' + ids + '")';
						eval(evalStr);
					}
				},
				error : function() {
					alert("网络请求失败!");
				}
			});
		},
		JS2C_InitializeUsbAndThread : function() {

		},
		JS2C_GetNewBatchId : function() {
			return "new batchId";
		},
		JS2C_GetBatchInfo : function(bId) {
			$
					.post(
							"line/getbatchdetail2.htm",
							{
								"batchId" : bId
							},
							function(r) {
								if (r.result == "1") {

									$("p#firstp").html("单号 : " + r.b);
									$("p#secondp").html(
											"生产完成时间 : " + r.ft
													+ "&nbsp;&nbsp;入库时间 : "
													+ r.sitm);

									var html = "";
									for ( var i = 0; i < r.ps.length; i++) {
										html = html
												+ "<tr id='" + r.ps[i].pid + "' class='datarow'><td>"
												+ r.ps[i].nc
												+ "</td><td>"
												+ r.ps[i].pdn
												+ "</td><td>"
												+ r.ps[i].num
												+ "</td>"
												+ "</tr><tr style='display: none'><td colspan='3' style='word-wrap: break-word; word-break: break-all;'>"
												+ "箱号:<br/>";
										for ( var j = 0; j < r.ps[i].boxes.length; j++) {
											if (j != (r.ps[i].boxes.length - 1)) {
												html = html
														+ r.ps[i].boxes[j].ids2e
														+ ","
											} else {
												html = html
														+ r.ps[i].boxes[j].ids2e;
											}
										}
										html = html + "</td></tr>"

									}

									$("tbody#statics").html(html);

									$(".datarow").hover(function() {
										$(this).css("cursor", "pointer");
									});

									for ( var i = 0; i < r.ps.length; i++) {
										$("tr#" + r.ps[i].pid)
												.click(
														function() {
															if ($(this).next(
																	"tr").css(
																	"display") == "none") {
																$(this)
																		.next(
																				"tr")
																		.css(
																				"display",
																				"");
															} else {
																$(this)
																		.next(
																				"tr")
																		.css(
																				"display",
																				"none");
															}

														});

									}

									$("p#totalnum").html("总箱数 : " + r.sum);

								} else {
									$.alert(r.err);
								}

							}, "json");

			//return "{'btm':'2012-12-05 17:18:47','b':'"
			//		+ bId
			//		+ "','sum':'5','pdtm':'01212050','pcts':[{'n':'浓香型皇台酒','pcode':'ht003','pcnt':'10','ids2e':'336~337,339~340,520'},{'n':'皇台酒','pcode':'ht002','pcnt':'20','ids2e':'336~337,339~340,520dfghjkl,2324234,23424234,23423424323243242342342342342342342342,23423423423,2344243'}]}";
		},
		JS2C_UploadLogInfo : function(callBkFunc) {
			setTimeout(callBkFunc + "()", 3000);
		},
		JS2C_UpdateBoxInfo : function() {
			return 1;
		},
		JS2C_GetServerDate : function() {
			return "";
		}
	};

	if (!localMode) {
		ExternalFunctions = window.external;
	}

	var singleReader;
	var net;
	var boxReader;

	function UploadLogInfoDone() {
		loadingEnd();
	}
	function GetExitResultDone(success) {
		loadingEnd();
		if (success == "1") {
			window.location.href = "login.html";
		}
	}
	function show() {
		var dateStr = new Date().Format("yyyy-MM-dd hh:mm:ss");
		$("#nowDiv").html(dateStr);
		setTimeout("show()", 1000);
	}

	function loadInfo() {
		ExternalFunctions.JS2C_InitializeIndexInfo();
		globalVal = ExternalFunctions.JS2C_GetParameterInfo();
		globalValJson = eval("(" + globalVal + ")");

		$("#current-batchid").html(globalValJson.batchid);
		$("#current-batch-box").html(globalValJson.box + "]");
		$("#current-product").html(globalValJson.pname);
		$("#current-product-barcode").html(globalValJson.barcode);
		$("#cbottle").html(globalValJson.cbottle);
		$("#cbox").html(globalValJson.cbox);
		$("#about").html(globalValJson.v);

		var dateLocal = new Date().Format("yyyy-MM-dd hh:mm:ss");
		var dateServer = ExternalFunctions.JS2C_GetServerDate();

		if (dateLocal.substr(0, 10) == dateServer || dateServer == "") {
			$("#nowDiv-flag img").remove();
		} else {
			$("#nowDiv-flag")
					.append(
							"<img src='css/images/time-changed-flag.png' title='生产日期与系统日期不符！'></img>");
		}

		ExternalFunctions.JS2C_InitializeUsbAndThread();
	}

	function C2JS_getReaderInfo(r) {
		//{"cbottle":"value","sbatch":"value","cbox":"value","r1":"value","r2":"value","net":"value"}
		if (r) {
			r = eval("(" + r + ")");
			if (r) {
				var cbottle = $("#cbottle").html();
				var sbatch = $("#sbatch").html();
				var cbox = $("#cbox").html();

				if (r.cbottle) {
					if (cbottle != r.cbottle) {
						$("#cbottle").html(r.cbottle);
					}
				}

				if (r.sbatch) {
					if (sbatch != r.sbatch) {
						$("#sbatch").html(r.sbatch);
					}
				}

				if (r.cbox) {
					if (cbox != r.cbox) {
						$("#cbox").html(r.cbox);
					}
				}

				if (r.r1) {
					if (r.r1 != singleReader) {
						singleReader = r.r1;
						$("#singleReaderFlag").attr('class',
								changeUsbStatusToDisplay(singleReader));
						$("#singleReader").html(r.r1);
					}
				}

				if (r.r2) {
					if (r.r2 != boxReader) {
						boxReader = r.r2;
						$("#boxReaderFlag").attr('class',
								changeUsbStatusToDisplay(boxReader));
						$("#boxReader").html(r.r2);
					}
				}

				if (r.net) {
					if (r.net != net) {
						net = r.net;
						$("#netFlag").attr('class',
								changeNetStatusToDisplay(net));
						$("#net").html(r.net);
					}
				}
			}
		}
	}

	function changeUsbStatusToDisplay(s) {
		var statusToDisplay;
		switch (s) {
		case '0':
			statusToDisplay = 'usb-icon';
			break;
		case '1':
			statusToDisplay = 'usb-unknow-icon';
			break;
		default:
			statusToDisplay = 'usb-err-icon';
		}
		return statusToDisplay;
	}

	function changeNetStatusToDisplay(s) {
		var statusToDisplay;
		switch (s) {
		case '0':
			statusToDisplay = 'net-icon';
			break;
		case '-1':
			statusToDisplay = 'net-err-icon';
			break;
		default:
			statusToDisplay = 'net-err-icon';
		}
		return statusToDisplay;
	}

	function C2JS_finishedBatch() {
		var batchid = ExternalFunctions.JS2C_GetNewBatchId();
		if (batchid != "0") {
			$("#current-batchid").html(batchid);
			$("#cbox").html('0');
		}
	}

	function printpart(id_str) {
		var el = document.getElementById(id_str);
		var iframe = document.createElement('IFRAME');
		var doc = null;
		iframe
				.setAttribute('style',
						'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
		document.body.appendChild(iframe);
		doc = iframe.contentWindow.document;
		doc
				.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
						+ '<link rel="stylesheet" type="text/css" href="../css/Jcss.css" />'
						+ '<link href="../jquery/css/redmond/jquery-ui-1.9.0.custom.css" rel="../css/stylesheet" />'
						+ '<style>@media print{button{display:none} tr{display:block}}</style>');
		doc.write(el.innerHTML);
		doc.close();
		iframe.contentWindow.focus();
		iframe.contentWindow.print();
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			document.body.removeChild(iframe);
		}
	}

	function C2JS_getBatchList() {
		loadingBegin();
		ExternalFunctions.JS2C_GetAllBatchId("C2JS_getBatchListDone");
	}
	function C2JS_getBatchListDone(b) {
		loadingEnd();
		var bl = eval("(" + b + ")");
		var blArray = bl.ids.split(",");

		$("#batch-list tr").remove();
		for ( var i = 0; i < blArray.length; i++) {
			if (blArray[0] != "") {
				$("#batch-list")
						.append(
								"<tr style='cursor:pointer'><td class='batch-list-color' onmouseover=mouseoverBatchList(this) onmouseout=mouseoutBatchList(this) onclick=clickBatchList('"
										+ blArray[i]
										+ "')>"
										+ blArray[i]
										+ "</td></tr>");
			}
		}

		if (blArray[0] != "") {
			clickBatchList(blArray[0]);
		}
		$("#storage-in").dialog("open");
	}

	function mouseoverBatchList(item) {
		$(item).css('border', 'solid 1px black');
	}

	function mouseoutBatchList(item) {
		$(item).css('border', 'solid 1px #8DB9DB');
	}

	function clickBatchList(i) {
		//"{'btm':'2012-12-05 17:18:47','b':'A012012120500400','sum':'5','pdtm':'01212050','pcts':[{'n':'浓香型皇台酒','pcode':'ht003','pcnt':'10','ids2e':'336~337,339~340,520'},{'n':'皇台酒','pcode':'ht002','pcnt':'20','ids2e':'336~337,339~340,520'}]}";
 		ExternalFunctions.JS2C_GetBatchInfo(i);
	}

	function showBatchInfoDetail(item) {
		var b = $(item);
		if (b.html() == "+") {
			b.html("-");
		} else {
			b.html("+");
		}
		var t = b.parents('table:first');
		var tr = t.find('tr:last');
		tr.slideToggle();
	}

	function C2JS_getLogInfo(i) {
		logCount++;
		//{flag:'-1/0/1',title:'类型描述',detail:'箱子：1,2,3,4,5;瓶子：6,7,8,9,0;'}
		var syslogDiv = $("#syslog").parent("div");
		if (i) {
			var info = eval("(" + i + ")");
			var time = $("#nowDiv").html();
			var color;
			var image;

			switch (info.flag) {
			case "0":
				color = "black";
				image = "correct-log-flag";
				break;
			case "1":
				color = "red";
				image = "err-log-flag";
				break;
			default:
				color = "orange";
				image = "warn-log-flag";
				break;
			}

			if (logCount > logCacheCount) {
				$("table#syslog>tbody>tr:last").remove();
			}

			var text = "<tr style='height:20px;cursor: pointer;color:"
					+ color
					+ "' onmouseover=mouseoverLogList(this) onmouseout=mouseoutLogList(this) ondblclick=mousedbClick(this)>"
					+ "<td style='width: 5%; valign: middlle;'>"
					+ "<div class='"+ image +"'>&nbsp;</div>"
					+ "</td><td style='width:20%'>"
					+ time
					+ "</td><td style='width:15%'>"
					+ info.title
					+ "</td><td style='word-wrap: break-word; word-break: break-all;'>"
					+ info.detail
					+ "</td><td style='width:80px'><button onclick=delLog(this) style='display: none'>删除</button></td></tr>";

			$("table#syslog").prepend(text);
			//$(text).insertAfter("#log-tr");
			//syslogDiv.scrollTop(syslogDiv[0].scrollHeight);
		}
	}

	function C2JS_getBottoleLogInfo(flag, detail) {
		bottleLogCount++;

		//{flag:'-1/0/1',detail:'一串字体'}
		if (flag) {
			var time = $("#nowDiv").html();
			var color;
			var image;

			switch (flag) {
			case "0":
				color = "black";
				image = "correct-log-flag";
				break;
			case "1":
				color = "red";
				image = "err-log-flag";
				break;
			default:
				color = "orange";
				image = "warn-log-flag";
				break;
			}

			if (bottleLogCount > logCacheCount) {
				$("table#bottlelog>tbody>tr:last").remove();
			}

			var text = "<tr style='height:20px;cursor: pointer;color:"
					+ color
					+ "' onmouseover=mouseoverLogList(this) onmouseout=mouseoutLogList(this)>"
					+ "<td style='width: 5%; valign: middlle;'>"
					+ "<div class='"+ image +"'>&nbsp;</div>"
					+ "</td><td style='width:40%'>"
					+ time
					+ "</td><td style='word-wrap: break-word; word-break: break-all;'>"
					+ detail
					+ "</td><td style='width:80px'><button onclick=delLog(this) style='display: none'>删除</button></td></tr>";

			$("table#bottlelog").prepend(text);
			//$(text).insertAfter("#bottle-log-tr");
		}
	}

	function mouseoverLogList(item) {
		item.bgColor = '#EAF4FD'
		$(item).children("td:last").children('button').css("display", "block");
	}

	function mouseoutLogList(item) {
		item.bgColor = ''
		$(item).children("td:last").children('button').css("display", "none");
	}

	function mousedbClick(item) {
		if (item.style.color == "red") {
			var text = $(item).children("td:eq(3)").html();
			var box = text.substring(text.indexOf("合法箱号：") + 5, text.indexOf(
					"；", text.indexOf("合法箱号：")));
			box = box == "无" ? "" : box;

			var bottles = new Array();

			var bottleString = text.substring(text.indexOf("合法瓶号：") + 5, text
					.indexOf("；", text.indexOf("合法瓶号：")));
			bottleString = (bottleString == "无" ? "" : bottleString);

			var unRegistBottleString = "";
			if (text.indexOf("未注册产品瓶号：") > 0) {
				unRegistBottleString = text.substring(
						text.indexOf("未注册产品瓶号：") + 8, text.indexOf("；", text
								.indexOf("未注册产品瓶号：")));
			}

			if (unRegistBottleString != "") {
				if (bottleString == "") {
					bottleString = unRegistBottleString;
				} else {
					bottleString = bottleString + ',' + unRegistBottleString;
				}

			}

			bottles = bottleString.split(',');

			$("#box-number").val('');
			$("#box-product-time").val('');
			$("#err-box-message").html('');
			for ( var i = 1; i <= 6; i++) {
				$("#bottle-number-" + i).val('');
			}

			$("#box-batch-id").val($('#current-batchid').html());
			$("#box-product-time").val($(item).children("td:eq(1)").html());
			$("#box-number").val(box);

			var len;
			len = bottles.length >= 6 ? 6 : bottles.length;

			for ( var i = 1; i <= len; i++) {
				$("#bottle-number-" + i).val(bottles[i - 1]);
			}

			$("#dialog-manual-box").dialog('open');
		}
	}

	function resetLog() {
		logCount = 0;
		$("table#syslog").html("<tr><td><td><tr>");
	}

	function resetBottleLog() {
		bottleLogCount = 0;
		$("table#bottlelog").html("<tr><td><td><tr>");
		//$("#bottlelog").append("<tr id='bottle-log-tr'><td></td></tr>");
	}

	function delLog(item) {
		logCount = logCount - 1;
		$(item).parent('td').parent('tr').remove();
	}

	function show() {
		var dateStr = new Date().Format("yyyy-MM-dd hh:mm:ss");
		$("#nowDiv").html(dateStr);
		if (dateStr.substr(14, 5) == "00:00") {
			var netFlag = $("#net").html();
			if (netFlag != "0") {
				$('#dialog-net').dialog('open');
				setTimeout(function() {
					$('#dialog-net').dialog('close');
				}, 5000);
			}
		}

		if (dateStr.substr(18, 1) == "0") {
			loadLineInfo();
		}
		setTimeout("show()", 1000);
	}

	function loadLineInfo() {
		$.ajax({
			url : 'line/info.htm',
			type : "POST",
			success : function(data) {
				if (data != null && data != "" && data.length > 0) {
					var d = data[0];
					if (d.bottleCnt) {
						$("#cbottle").html(d.bottleCnt);
					}
					if (d.boxCnt) {
						$("#cbox").html(d.boxCnt);
					}
					if (d.batchCnt) {
						$("#sbatch").html(d.batchCnt);
					}
					if (d.batchId) {
						$("#current-batchid").html(d.batchId);
					}
					if (d.pdName) {
						$("#current-product").html(d.pdName);
					}
					if (d.barCode) {
						$("#current-product-barcode").html(d.barCode);
					}
					if (d.batchBoxNum) {
						$("#current-batch-box").html(d.batchBoxNum + "]");
					}
					if (d.boxBottleNum) {

					}
					if (d.bottleReaderFlag) {
						$("#singleReaderFlag").attr('class',
								changeUsbStatusToDisplay(d.bottleReaderFlag));
						$("#singleReader").html(d.bottleReaderFlag);

					}
					if (d.boxReaderFlag) {
						$("#boxReaderFlag").attr('class',
								changeUsbStatusToDisplay(d.boxReaderFlag));
						$("#boxReader").html(d.boxReaderFlag);
					}
					if (d.netFlag) {
						$("#netFlag").attr('class',
								changeNetStatusToDisplay(d.netFlag));
						$("#net").html(d.netFlag);
					}
				}
			},
			error : function() {
				alert("网络请求失败!");
			}
		});
	}

	Date.prototype.Format = function(fmt) {
		var o = {
			"M+" : this.getMonth() + 1, //月份 
			"d+" : this.getDate(), //日 
			"h+" : this.getHours(), //小时 
			"m+" : this.getMinutes(), //分 
			"s+" : this.getSeconds(), //秒 
			"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
			"S" : this.getMilliseconds()
		//毫秒 
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
		for ( var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
						: (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	};

	$(function() {

		loadInfo();

		loadLineInfo();

		$("#box-product-time").datepicker({
			dateFormat : "yy-mm-dd",
			onSelect : function() {
				var date = $(this).val();
				var time = $("#nowDiv").html();
				$(this).val(date + " " + time.substr(11, 8));
			}
		});

		$("#button-batch-log").click(function() {
			C2JS_getBatchList();
		});

		$("#button-manual-box").click(function() {
			$("#box-number").val('');
			$("#box-product-time").val('');
			$("#err-box-message").html('');
			for ( var i = 1; i <= 6; i++) {
				$("#bottle-number-" + i).val('');
			}

			$("#box-product-time").val($("#nowDiv").html());
			$("#box-batch-id").val($("#current-batchid").html());
			$("#dialog-manual-box").dialog('open');
		});

		$("#button-upload").click(function() {
			loadingBegin();
			ExternalFunctions.JS2C_UploadLogInfo("UploadLogInfoDone");
		});

		$("#button-finish").click(function() {
			C2JS_finishedBatch();
		});

		$("#cbottle-display").mouseover(function() {
			$("#cbottle-display").css({
				"border" : "2px solid #E17009"
			});
		});
		$("#cbottle-display").mouseout(function() {
			$("#cbottle-display").css({
				"border" : "2px solid #6EA7D1"
			});
		});

		$("#sbatch-display").mouseover(function() {
			$("#sbatch-display").css({
				"border" : "2px solid #E17009"
			});
		});
		$("#sbatch-display").mouseout(function() {
			$("#sbatch-display").css({
				"border" : "2px solid #6EA7D1"
			});
		});

		$("#cbox-display").mouseover(function() {
			$("#cbox-display").css({
				"border" : "2px solid #E17009"
			});
		});
		$("#cbox-display").mouseout(function() {
			$("#cbox-display").css({
				"border" : "2px solid #6EA7D1"
			});
		});

		$("#button-out").click(function() {
			loadingBegin();
			ExternalFunctions.JS2C_GetExitResult("GetExitResultDone");
		});

		$("#button-change-password").click(function(event) {
			$("#old-password").val('');
			$("#new-password").val('');
			$("#repeat-new-password").val('');
			$("#changepassword").dialog("open");
			event.preventDefault();
		});

		$("#button-about").click(function() {
			$("#dialog-about").dialog("open");
		});

		$("#dialog-about").dialog({
			autoOpen : false,
			width : 400,
			height : 300,
			modal : true,
			buttons : [ {
				text : "关闭",
				click : function() {
					$(this).dialog("close");
				}
			} ]
		})

		$("#storage-in")
				.dialog(
						{
							autoOpen : false,
							width : 1000,
							height : 550,
							modal : true,
							buttons : [
									{
										text : "刷新",
										click : function() {
											C2JS_getBatchList();
										}
									},
									{
										text : "关闭",
										click : function() {
											$(this).dialog("close");
										}
									},
									{
										text : "打印",
										click : function() {
											var b = $("p#firstp").html();
											var n = b.indexOf(":") + 2;
											var batchid = b.substring(n);
											//var flag = clickBatchList(batchid);
											//if (flag == "1") {
											$("div#printBlock")
													.printElement(
															{
																overrideElementCSS : [
																		'../css/default.css',
																		'../jquery/redmond/jquery-ui-1.9.0.custom.min.css',
																		'../css/print.css' ]
															});
											//}
										}
									} ]
						});

		$("#dialog-manual-box")
				.dialog(
						{
							autoOpen : false,
							width : 650,
							modal : true,
							buttons : [
									{
										text : "确定",
										click : function() {
											var batch = $('#box-batch-id')
													.val();
											var time = $('#box-product-time')
													.val();
											var box = $('#box-number').val();

											var bottleErrFlag = 0;
											var bottleErrMes = "";

											var bottleString = "";

											for ( var i = 1; i <= 6; i++) {
												if ($('#bottle-number-' + i)
														.val()) {
													if (/[^\d]/.test($(
															'#bottle-number-'
																	+ i).val())) {
														bottleErrMes = '瓶号' + i
																+ '：必须为数字！';
														bottleErrFlag = 1;
														break;
													} else {
														if (i == 1) {

															bottleString = $(
																	'#bottle-number-'
																			+ i)
																	.val();

														} else {
															bottleString = bottleString
																	+ ','
																	+ $(
																			'#bottle-number-'
																					+ i)
																			.val();
														}
													}
												}
											}

											var bottleRepeatFlag = 0;

											if (bottleString != "") {
												var bottles = new Array();
												bottles = bottleString
														.split(",");

												for ( var i = 0; i < bottles.length; i++) {
													if (bottleString
															.replace(
																	bottles[i],
																	"")
															.indexOf(bottles[i]) > -1) {
														bottleRepeatFlag = 1;
														break;
													}
												}
											}

											if (!/\d{4}[-]\d{2}[-]\d{2}$/
													.test(time.substring(0, 10))) {
												$('#err-box-message').html(
														'日期格式不正确！');
											} else if (!box) {
												$('#err-box-message').html(
														'箱子不能为空！');
											} else if (/[^\d]/.test(box)) {
												$('#err-box-message').html(
														'箱号必须为数字！');
											} else if (bottleErrFlag == 1) {
												$('#err-box-message').html(
														bottleErrMes);
											} else if (!bottleString) {
												$('#err-box-message').html(
														'瓶子数量为0！');
											} else if (!batch) {
												$('#err-box-message').html(
														'单号不能为空！');
											} else if (!time) {
												$('#err-box-message').html(
														'时间不能为空！');
											} else if (bottleRepeatFlag == 1) {
												$('#err-box-message').html(
														'瓶号不能重复！');
											} else {
												var success = ExternalFunctions
														.JS2C_UpdateBoxInfo(
																box,
																bottleString,
																batch, time);
												if (success == "1") {
													var text = "<tr style='height:20px;color:black' "
															+ "onmouseover=mouseoverLogList(this) onmouseout=mouseoutLogList(this) ondblclick=mousedbClick(this)>"
															+ "<td style='width: 5%; valign: middlle;'>"
															+ "<div class='correct-log-flag'>&nbsp;</div>"
															+ "</td><td style='width:20%'>"
															+ time
															+ "</td><td style='width:15%'>"
															+ "手工装箱成功"
															+ "</td><td style='word-wrap: break-word; word-break: break-all;'>"
															+ "合法箱号："
															+ box
															+ "；"
															+ "合法瓶号："
															+ bottleString
															+ "；"
															+ "</td></tr>";

													$("table#syslog").prepend(
															text);

													$(this).dialog("close");
												}
											}
										}
									}, {
										text : "取消",
										click : function() {
											$(this).dialog("close");
										}
									} ]
						});

		$("#changepassword")
				.dialog(
						{
							autoOpen : false,
							width : 450,
							modal : true,
							buttons : [
									{
										text : "确定",
										click : function() {
											var a = $("#old-password").val();
											var b = $("#new-password").val();
											var c = $("#repeat-new-password")
													.val();

											var json = "{" + "'oldpwd':'" + a
													+ "'," + "'newpwd':'" + b
													+ "'," + "'repwd':'" + c
													+ "'}";
											var success = ExternalFunctions
													.JS2C_GetPasswordUpdateResult(json);
											if (success == "1") {
												$(this).dialog("close");
											}
										}
									}, {
										text : "取消",
										click : function() {
											$(this).dialog("close");
										}
									} ]
						});

		$("#reset-syslog").click(function() {
			resetLog();
		});

		$("#reset-bottle-log").click(function() {
			resetBottleLog();
		});

		$('#dialog-net').dialog({
			autoOpen : false,
			width : 400,
			modal : true,
			buttons : [ {
				text : "关闭",
				click : function() {
					$(this).dialog("close");
				}
			} ]
		});
	});
</script>
</head>
<body onload="show()" onContextMenu="return false">
	<table style="height: 100%; width: 100%; top: 0px;" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="height: 100%;">
				<table style="width: 100%; height: 100%; top: 0px;">
					<tr style="height: 70px;">
						<td colspan="1"><div>
								<table class="top-line">
									<tr
										style="vertical-align: middle; width: 50%; height: 100%; border-spacing: 0px;">
										<td style="width: 50px;"><button id="button-batch-log">
												<img src="css/images/search-batch.png"></img>
												<div>单据查询</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-finish">
												<img src="css/images/finish-batch.png"></img>
												<div>结束一单</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-manual-box">
												<img src="css/images/manual-box.png"></img>
												<div>手工装箱</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-upload">
												<img src="css/images/upload-log.png"></img>
												<div>提交日志</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-change-password">
												<img src="css/images/change-password.png"></img>
												<div>修改密码</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-out">
												<img src="css/images/out.png"></img>
												<div>退出</div>
											</button></td>
										<td style="width: 50px; display: none;"><button
												id="button-about">
												<img src="css/images/about.png"></img>
												<div>关于</div>
											</button></td>
										<td></td>
									</tr>
								</table>
							</div>
						</td>
					</tr>

					<tr style="height: 100px;">
						<td><table style="width: 100%;">
								<tr style="font-size: 1em; font-weight: bolder;">
									<td style="width: 100px;">当前单号：</td>
									<td><span id="current-batchid"></span><span>[每单箱数：</span><span
										id="current-batch-box">]</span></td>
									<td style="width: 300px;"></td>
									<td>
										<div style="text-align: right; font-weight: bolder;">
											<span id="current-product"></span><span>(</span><span
												id="current-product-barcode"></span><span>)</span>
										</div></td>
								</tr>
								<tr
									style="width: 100%; height: 100px; font-size: 2.5em; font-weight: bolder;">
									<td style="text-align: center;" colspan="4">生产时间：<span
										id="nowDiv"></span><span id="nowDiv-flag">&nbsp;&nbsp;&nbsp;&nbsp;</span>
									</td>
								</tr>
							</table>
						</td>
					</tr>

					<tr style="position: relative; height: 40%;">
						<td style="position: relative; height: 40%;">
							<table
								style="position: relative; height: 100%; width: 100%; text-align: center;">
								<tr style="width: 100%; height: 100%">
									<td style="text-align: center; width: 33.3%; height: 100%;">
										<table style="width: 100%; height: 100%">
											<tr>
												<td style="text-align: center; height: 20%"><h2>未装箱瓶数</h2>
												</td>
											</tr>
											<tr>
												<td
													style="height: 80%; vertical-align: middle; text-align: center; width: 33.3%;">
													<div id="cbottle-display" class="main-display">
														<table style="width: 100%; height: 100%">
															<tr>
																<td id="cbottle" style="vertical-align: middle;"></td>
															</tr>
														</table>
													</div>
												</td>
											</tr>
										</table>
									</td>
									<td style="text-align: center; width: 33.3%; height: 100%;">
										<table style="width: 100%; height: 100%">
											<tr style="text-align: center; height: 20%">
												<td><h2>本单完成箱数</h2></td>
											</tr>
											<tr>
												<td
													style="height: 80%; vertical-align: middle; text-align: center;">
													<div id="cbox-display" class="main-display">
														<table style="width: 100%; height: 100%">
															<tr>
																<td id="cbox" style="vertical-align: middle;">0</td>
															</tr>
														</table>
													</div>
												</td>
											</tr>
										</table>
									</td>
									<td style="text-align: center; width: 33.3%; height: 100%;">
										<table style="width: 100%; height: 100%">
											<tr style="text-align: center; height: 20%">
												<td><h2>已完成单数</h2></td>
											</tr>
											<tr>
												<td
													style="height: 80%; vertical-align: middle; text-align: center; width: 33.3%;">
													<div id="sbatch-display" class="main-display">
														<table style="width: 100%; height: 100%">
															<tr>
																<td id="sbatch" style="vertical-align: middle;">0</td>
															</tr>
														</table>
													</div>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr style="height: 30%;">
						<td style="height: 25%; display: none;">
							<div>
								<button id="reset-syslog" style="position: relative; left: 3%;">清除日志</button>
							</div>

							<div
								style="position: relative; height: 80%; width: 94%; left: 3%; overflow: auto; border: 1px #89B7DA solid; font-size: 0.8em; overFlow-x: hidden;">
								<table id="syslog" style="width: 100%;" border="0"
									cellpadding="0" cellspacing="0">

								</table>
							</div></td>
					</tr>

					<tr style="height: 50px;" class="base-line">
						<td>
							<table style="width: 100%; bottom: 0px; height: 20px;">
								<tr>
									<td style="text-align: right; width: 15%;">单瓶读卡器:</td>
									<td id="singleReaderFlag" class="usb-err-icon"><span
										style="position: relative; left: 25px;">[<span
											id="singleReader">-1</span>] </span></td>
									<td style="text-align: right; width: 15%;">装箱读卡器:</td>
									<td id="boxReaderFlag" class="usb-err-icon"><span
										style="position: relative; left: 25px;">[<span
											id="boxReader">-1</span>] </span></td>
									<td style="text-align: right; width: 15%;">网络连接:</td>
									<td id="netFlag" class="net-err-icon"><span
										style="position: relative; left: 25px;">[<span id="net">-1</span>]
									</span></td>
								</tr>
							</table>
						</td>
					</tr>
				</table></td>

			<td
				style="width: 400px; height: 92%; padding: 2px; vertical-align: text-top; display: none;">
				<table style="border: 1px solid #89B7DA; height: 100%; width: 100%;">
					<tr>
						<td>
							<div
								style="height: 40px; text-align: center; width: 99.5%; background-color: #89B7DA; border: 1px solid #4297D7;">
								<div style="height: 10px;"></div>
								<span
									style="font-size: 1.2em; color: white; font-weight: bolder;">单瓶日志</span>
								<div style="height: 10px;"></div>
							</div>

							<button id="reset-bottle-log"
								style="position: relative; font-size: 0.8em;">清除日志</button></td>
					</tr>
					<tr>
						<td style="height: 100%;">
							<div
								style="position: relative; height: 100%; width: 99%; top: 0px; left: 1px; overflow: auto; border: 1px #89B7DA solid; font-size: 0.8em; overFlow-x: hidden; background-color: white;">
								<table id="bottlelog" style="position: relative; width: 100%;"
									border="0" cellpadding="0" cellspacing="0">
								</table>
							</div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

	<div id="storage-in" title="入库单"
		style="display: none; overFlow-x: hidden;">
		<table class="table1" border="1" cellpadding="0" cellspacing="0"
			style="border: solid 1px black; height: 100%; border-collapse: collapse; width: 100%;">
			<tr>
				<td
					style="position: relative; height: 100%; width: 202px; vertical-align: top">
					<div
						style="height: 100%; width: 202px; overflow: scroll; overFlow-x: hidden;">
						<table id="batch-list" style="width: 90%;">
						</table>
					</div>
				</td>
				<td style="width: 10px; border: none;"></td>
				<td
					style="vertical-align: top; border: none; height: 95%; overFlow-x: hidden; width: 100%;"
					id="batch-info">
					<div id="dialog" title="入库单">
						<div id='printBlock'>
							<h3 align='center'>入库单</h3>

							<p id='firstp' align='left'></p>

							<p id='secondp' align='left'></p>
							<table class='instorageListClass'
								style="border: 1px solid #2575B4; font-family: ''; font-size: 1em; height: auto; width: 100%; border-collapse: collapse;"
								cellpadding="0px" cellspacing="0px" border='1px'>
								<thead>
									<tr>
										<th class="storage-in-th">产品代码</th>
										<th class="storage-in-th">产品名称</th>
										<th class="storage-in-th">箱数</th>
									</tr>
								</thead>
								<tbody id="statics">
								</tbody>
							</table>
							<p id="totalnum" align='right'></p>

							<p align='right'>
								<span style='padding-right: 80px'>经手人:</span><span
									style='padding-right: 60px'>保管人:</span>
							</p>
						</div>
					</div>
				</td>
				<td style="width: 10px; border: none;"></td>
			</tr>
		</table>
	</div>

	<div id="changepassword" title="修改密码" style="display: none;">
		<table>
			<tr>
				<td style="width: 250px">输入旧密码：</td>
				<td><input id="old-password" type="password"
					style="width: 210px" /></td>
			</tr>
			<tr>
				<td style="width: 250px">输入新密码：</td>
				<td><input id="new-password" type="password"
					style="width: 210px" /></td>
			</tr>
			<tr>
				<td style="width: 250px">再次输入新密码：</td>
				<td><input id="repeat-new-password" type="password"
					style="width: 210px" /></td>
			</tr>
		</table>
	</div>



	<div id="dialog-net" title="网络监测" style="display: none;">
		<p>请检查网络！</p>
	</div>

	<div id="dialog-about" title="关于    车间管理软件" style="display: none;">
		<p id="about"></p>
		<p>版权所有&copy; 上海质尊物联网科技有限公司</p>
	</div>

	<div id="dialog-manual-box" title="手动装箱" style="display: none;">
		<table style="width: 100%">
			<tr>
				<td style="width: 30%">单号：</td>
				<td><input id="box-batch-id" style="width: 80%;" />
				</td>
			</tr>
			<tr>
				<td>生产时间：</td>
				<td><input id="box-product-time" type="text" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>箱标：</td>
				<td><input id="box-number" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标1：</td>
				<td><input id="bottle-number-1" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标2：</td>
				<td><input id="bottle-number-2" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标3：</td>
				<td><input id="bottle-number-3" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标4：</td>
				<td><input id="bottle-number-4" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标5：</td>
				<td><input id="bottle-number-5" style="width: 80%" />
				</td>
			</tr>
			<tr>
				<td>瓶标6：</td>
				<td><input id="bottle-number-6" style="width: 80%" />
				</td>
			</tr>
		</table>
		<div id="err-box-message" style="color: red"></div>
	</div>

	<div class="loading"></div>
</body>
</html>